
package botlab.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.JLabel;
import javax.swing.Timer;

/**
 *
 * @author Quentin
 */
public class Notifier implements ActionListener
{
    private static final Notifier instance = new Notifier();
    private JLabel notifications;
    private HashMap<String,ArrayList<String>> notes; 
    private Timer timer;
    private final int delay = 7000;
    private int index;
            
    private String state;

    public static Notifier getInstance()
    {
        return instance;
    }
    
    public Notifier()
    {
        notes = new HashMap<String,ArrayList<String>>();
        initNotes();
        index=0;
        timer = new Timer(delay, this);
        timer.setInitialDelay(0);
        timer.start();
        
    }
    
    private void initNotes()
    {
        ArrayList homeNotes = new ArrayList();
            homeNotes.add("Please choose the level you want to play.");
            homeNotes.add("Click Previous and Next to switch levels, Select to choose the level and Cancel to exit game.");
        ArrayList editorNotes = new ArrayList();
            editorNotes.add("Use the tool bar above to perform usual actions.");
            editorNotes.add("When flying over buttons, a tooltip should appear.");
            editorNotes.add("Take care to save your code before loading another.");
            editorNotes.add("WARNING : What you type in the editor will be executed in loop.");
            editorNotes.add("To visit level, leave editor blank, start render and switch to \"flyby\" camera view.");
        ArrayList errorsNotes = new ArrayList();
            errorsNotes.add("You've made mistakes, please correct your code before launching render.");
        ArrayList renderNotes = new ArrayList();
            renderNotes.add("You're currently in \"fixed\" camera view.");
            renderNotes.add("IMPORTANT : You have to click in the scene to grab keyboard focus.");
            renderNotes.add("Hit TAB to switch camera view.");
        ArrayList renderCam2Notes = new ArrayList();
            renderCam2Notes.add("You're in \"flyby\" camera view.");
            renderCam2Notes.add("Use Z Q S D and A W keys to move camera.");
            renderCam2Notes.add("Click and drag to rotate.");
        ArrayList renderCam3Notes = new ArrayList();
            renderCam3Notes.add("You're in \"chase\" camera view.");
            renderCam3Notes.add("The camera will follow the space ship.");
            renderCam3Notes.add("Click and drag to rotate.");
            renderCam3Notes.add("Use the mouse wheel to zoom in and out.");
        ArrayList renderTimeOutNotes = new ArrayList();
            renderTimeOutNotes.add("The time is over!");
            renderTimeOutNotes.add("Click the stop button to try again.");
        ArrayList renderCollisionNotes = new ArrayList();
            renderCollisionNotes.add("The space ship collide with another object!");
            renderCollisionNotes.add("Click the stop button to try again.");
        ArrayList levelNotes = new ArrayList();
            levelNotes.add("Click Previous or Next to switch levels and Select to choose the level");
            levelNotes.add("Click Cancel to return to editor and keep last level.");
            
        notes.put("home", homeNotes);
        notes.put("editor", editorNotes);
        notes.put("errors", errorsNotes);
        notes.put("render", renderNotes);
        notes.put("render2", renderCam2Notes);
        notes.put("render3", renderCam3Notes);
        notes.put("timeOut", renderTimeOutNotes);
        notes.put("collision", renderCollisionNotes);
        notes.put("level", levelNotes);
        
    }

    public void setNotifications(JLabel notifications)
    {
        this.notifications = notifications;
    }
    
    public void addNote(String state, String note)
    {
        if(notes.containsKey(state))
        {
            notes.get(state).add(note);
        }
        else
        {
            ArrayList l = new ArrayList<String>();
            l.add(note);
            notes.put(state,l);
        }
    }
    
    public void enterState(String state)
    {
        this.state = state;
        index=0;
        timer.restart();
    }

    public void actionPerformed(ActionEvent e)
    {
        if( notifications!=null && state!=null)
        {
            ArrayList<String> l = notes.get(state);
            notifications.setText("  "+l.get(index));
            index++;
            index%=l.size();
        }
    }
    
    
    
    
    
    
    
    
}
